<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?
$path = '../Mkart/';
include($path."common.php");
include($path."prod_fun.php");


switch($action){
//=====================================================
case "取消" :
//$page = $page1 ;

gotopage($page) ;
break;
//=====================================================
case "信用卡(一次付清)" :
if($consigenee_check == "Y"){
$consignee_name = $shopper_name ;
$consignee_tel = $shopper_tel ;
$consignee_phone = $shopper_phone ;
$consignee_zip = $shopper_zip ;
$consignee_address = $shopper_address ;
$consignee_mail = $shopper_mail ;
}
if(empty($shopper_name) or empty($shopper_phone) or empty($shopper_address) or empty($consignee_name) or empty($consignee_phone) or empty($consignee_address)){
$msg = "請輸入資料" ;
$page = "kart_order.php" ;
msgpop($msg) ;
}else{
$sql_num = "select * from kart_order order by order_id desc limit 1 " ;
$result_num = mysql_query($sql_num) ;
$row_num=mysql_fetch_object($result_num) ;
$num = $row_num->order_id ;
if(empty($num)){
$data_num = "OD000001" ;
}else{
$data_num = (substr($num, 0,2) . substr((1000000 + substr($num , 2,6) + 1) , 1 ,6)) ;
}
//============================================
$sql_add_order = "insert into kart_order set 
					order_id = '$data_num' , 
					order_type = '3' , 
					order_price = '$shop_amount' , 
					order_state = 'N' , 
					order_date = '' , 
					order_time = '' , 
					order_auth = '' ,
					order_invoice = '$invoice' , 
					order_invoiceno = '$invoice_no' 
					" ;
$result_add_order = mysql_query($sql_add_order) ;
//echo $sql_add_order ;
//============================================
$p_list = explode(",",$item_list) ;
$p_list_sum = explode(",",$item_list_sum) ;

for($n=0 ;$n<count($p_list) ; $n++){
$sql_add_list = "insert into order_item set 
					order_id = '$data_num' , 
					item_id = '$p_list[$n]' , 
					item_amount = '$p_list_sum[$n]'
					" ;
$result_add_list = mysql_query($sql_add_list) ;
//echo $sql_add_list ;
}
//============================================
$sql_add_shopper = "insert into order_shopper set 
					order_id = '$data_num' , 
					shopper_name = '$shopper_name' , 
					shopper_tel = '$shopper_tel' , 
					shopper_cellphone = '$shopper_phone' , 
					shopper_zip = '$shopper_zip' , 
					shopper_address = '$shopper_address' , 
					shopper_mail = '$shopper_mail' 
					" ;
$result_add_shopper = mysql_query($sql_add_shopper) ;
//============================================
$sql_add_consignee = "insert into order_consignee set 
					order_id = '$data_num' , 
					consignee_name = '$consignee_name' , 
					consignee_tel = '$consignee_tel' , 
					consignee_cellphone = '$consignee_phone' , 
					consignee_zip = '$consignee_zip' , 
					consignee_address = '$consignee_address' , 
					consignee_mail = '$consignee_mail' 
					" ;
$result_add_consignee = mysql_query($sql_add_consignee) ;
//============================================
$page = "order_check.php?oid=$data_num" ;
}
gotopage($page) ;
break;
//=====================================================
case "信用卡(分期付款)" :
if($consigenee_check == "Y"){
$consignee_name = $shopper_name ;
$consignee_tel = $shopper_tel ;
$consignee_phone = $shopper_phone ;
$consignee_zip = $shopper_zip ;
$consignee_address = $shopper_address ;
$consignee_mail = $shopper_mail ;
}

if(empty($shopper_name) or empty($shopper_phone) or empty($shopper_address) or empty($consignee_name) or empty($consignee_phone) or empty($consignee_address)){
$msg = "請輸入資料" ;
$page = "kart_order.php" ;
msgpop($msg) ;
}else{
$sql_num = "select * from kart_order order by order_id desc limit 1 " ;
$result_num = mysql_query($sql_num) ;
$row_num=mysql_fetch_object($result_num) ;
$num = $row_num->order_id ;
if(empty($num)){
$data_num = "OD000001" ;
}else{
$data_num = (substr($num, 0,2) . substr((1000000 + substr($num , 2,6) + 1) , 1 ,6)) ;
}
//============================================
$sql_add_order = "insert into kart_order set 
					order_id = '$data_num' , 
					order_type = '4' , 
					order_price = '$shop_amount' , 
					order_state = 'N' , 
					order_date = '' , 
					order_time = '' , 
					order_auth = '' ,
					order_invoice = '$invoice' , 
					order_invoiceno = '$invoice_no' 
					" ;
$result_add_order = mysql_query($sql_add_order) ;
//echo $sql_add_order ;
//============================================
$p_list = explode(",",$item_list) ;
$p_list_sum = explode(",",$item_list_sum) ;

for($n=0 ;$n<count($p_list) ; $n++){
$sql_add_list = "insert into order_item set 
					order_id = '$data_num' , 
					item_id = '$p_list[$n]' , 
					item_amount = '$p_list_sum[$n]'
					" ;
$result_add_list = mysql_query($sql_add_list) ;
//echo $sql_add_list ;
}
//============================================
$sql_add_shopper = "insert into order_shopper set 
					order_id = '$data_num' , 
					shopper_name = '$shopper_name' , 
					shopper_tel = '$shopper_tel' , 
					shopper_cellphone = '$shopper_phone' , 
					shopper_zip = '$shopper_zip' , 
					shopper_address = '$shopper_address' , 
					shopper_mail = '$shopper_mail' 
					" ;
$result_add_shopper = mysql_query($sql_add_shopper) ;
//============================================
$sql_add_consignee = "insert into order_consignee set 
					order_id = '$data_num' , 
					consignee_name = '$consignee_name' , 
					consignee_tel = '$consignee_tel' , 
					consignee_cellphone = '$consignee_phone' , 
					consignee_zip = '$consignee_zip' , 
					consignee_address = '$consignee_address' , 
					consignee_mail = '$consignee_mail' 
					" ;
$result_add_consignee = mysql_query($sql_add_consignee) ;
//============================================
$page = "order_check.php?oid=$data_num" ;
}
gotopage($page) ;
break;
//=====================================================
}

?>